<%--
    Document   : login
    Created on : Sep 14, 2011, 5:55:21 PM
    Author     : Phuong Giang
--%>

<%
            if (session.getAttribute("USER") != null) {
                response.sendRedirect("index.jsp");
            }
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Sign in</title>
        <link type="text/css" rel="stylesheet" href="styles/bootstrap-1.2.0.min.css"/>
        <script src="scripts/jquery-1.6.3.min.js" type="text/javascript" ></script>
        <style>
            fieldset > div, fieldset > legend {
                margin: auto;
                padding-left: 25% !important;
            }
        </style>
    </head>
    <body>
        <h1>Welcome to Chat Server</h1>

        <form action="LoginController" method="POST" name="login">
            <fieldset>
                <legend>Sign in</legend>
                <div id="server-error" class="clearfix error hidden">
                    <div> ${sessionScope["login-message"]} </div>
                </div>
                <div class="clearfix">
                    <label for="username">Username</label>
                    <div class="input">
                        <input class="xlarge" id="username" type="text" name="txtUsername" value="" />
                        <span class="help-inline hidden">Required</span>
                    </div>
                </div>
                <div class="clearfix">
                    <label for="password">Password</label>
                    <div class="input">
                        <input class="xlarge" id="password" type="password" name="txtPassword" value="" />
                        <span class="help-inline hidden">Required</span>
                    </div>
                </div>
                <div class="actions">
                    <input type="submit" value="Sign in" name="btnAction" class="primary btn">
                    <a class="info btn" href="signup.jsp">Sign Up</a>
                </div>
            </fieldset>

        </form>

        <script>
            if($.trim($("#server-error").text()) != "") {
                $("#server-error").removeClass("hidden");
            }
            var validateField = function(fieldID) {
                var input = $("#"+fieldID);
                if(input.val() == "") {
                    input.parents("div.clearfix").addClass("error");
                    input.addClass("error");
                    input.next(".help-inline").removeClass("hidden");
                    return false;
                } else {
                    input.parents("div.clearfix").removeClass("error");
                    input.removeClass("error");
                    input.next(".help-inline").addClass("hidden");
                    return true;
                }
            };
            var validateForm = function() {
                var u = validateField("username");
                var p = validateField("password");
                return u && p;
            }
            login.onsubmit = validateForm
        </script>
    </body>
</html>
